package com.jxs.android.weiget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jxs.android.ges.R;

public class WorkLogCommentItem extends LinearLayout {

	private EditText comment_content;
	private TextView index, comment_staff_name, comment_date;
	private boolean newCreat = false;

	public WorkLogCommentItem(Context context, int id) {
		super(context);
		init(context);
		index.setText(String.valueOf(id));

	}

	private void init(Context context) {
		LayoutInflater.from(context).inflate(R.layout.bu_work_log_comment_item, this);
		index = (TextView) findViewById(R.id.index);
		comment_content = (EditText) findViewById(R.id.comment_content);
		comment_staff_name = (TextView) findViewById(R.id.comment_staff_name);
		comment_date = (TextView) findViewById(R.id.comment_date);
	}

	public WorkLogCommentItem(Context context, AttributeSet attrs) {
		super(context, attrs);
		init(context);
		TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.WorkCommentItem);
		String indexstr = a.getString(R.styleable.WorkCommentItem_comment_index);
		String contentstr = a.getString(R.styleable.WorkCommentItem_comment_content);
		// sString staff_no =
		// a.getString(R.styleable.WorkCommentItem_comment_staff_no);
		String staff_name = a.getString(R.styleable.WorkCommentItem_comment_staff_name);
		String date = a.getString(R.styleable.WorkCommentItem_comment_date);
		boolean enabled = a.getBoolean(R.styleable.WorkCommentItem_comment_enable, false);
		comment_content.setText(contentstr);
		comment_staff_name.setText(staff_name);
		comment_date.setText(date);
		index.setText(indexstr);
		setEable(enabled);
		setGra(Gravity.CENTER);
		a.recycle();
	}

	private void setGra(int gravity) {
		comment_staff_name.setGravity(gravity);
		comment_content.setGravity(gravity);
		comment_date.setGravity(gravity);
	}

	public void setEable(boolean enabled) {
		comment_staff_name.setEnabled(enabled);
		comment_content.setEnabled(enabled);
		comment_date.setEnabled(enabled);
	}

	public void setValue(String contentStr, String staff_name, String date) {
		comment_content.setText(contentStr);
		comment_staff_name.setText(staff_name);
		comment_date.setText(date);
	}

	public String getComment_content() {
		return comment_content.getText().toString();
	}

	public String getComment_staff_name() {
		return comment_staff_name.getText().toString();
	}

	public String getComment_date() {
		return comment_date.getText().toString();
	}

	public String getIndex() {
		return index.getText().toString();
	}

	public boolean isNewCreat() {
		return newCreat;
	}

	public void setNewCreat(boolean newCreat) {
		this.newCreat = newCreat;
	}

	public void setBg(int resid) {
		index.setBackgroundResource(resid);
		comment_content.setBackgroundResource(resid);
		comment_staff_name.setBackgroundResource(resid);
		comment_date.setBackgroundResource(resid);

	}

	public void setTextStyleBlod() {
		index.setTypeface(Typeface.create(Typeface.SERIF, Typeface.BOLD));
		comment_content.setTypeface(Typeface.create(Typeface.SERIF, Typeface.BOLD));
		comment_staff_name.setTypeface(Typeface.create(Typeface.SERIF, Typeface.BOLD));
		comment_date.setTypeface(Typeface.create(Typeface.SERIF, Typeface.BOLD));
	}

}
